package ext.acae2.dms.parse.wc9;

import org.dom4j.Document;
import org.dom4j.Node;

import ext.acae2.dms.bean.EPMBuildHistoryBean;
import ext.acae2.util.LoadingXmlUtil;

public class ParseEPMBuildHistory {

	public static EPMBuildHistoryBean execute(String path) throws Exception{
		EPMBuildHistoryBean epmBuildHistoryBean = new EPMBuildHistoryBean();
		Document doc = LoadingXmlUtil.executeForDom4j(path);
		
		Node buildSourceNode = doc.selectSingleNode("/EPMBuildHistory/buildSource/ObjectReference/ufid");
		String buildSource = buildSourceNode.getText();
		String epmId = buildSource.substring(buildSource.lastIndexOf(":") + 1, buildSource.substring(0,buildSource.lastIndexOf("|")).lastIndexOf("|"));
		epmBuildHistoryBean.setEpmId(epmId);
		
		Node buildTargetNode = doc.selectSingleNode("/EPMBuildHistory/buildTarget/ObjectReference/ufid");
		String buildTarget = buildTargetNode.getText();
		String partId = buildTarget.substring(buildTarget.lastIndexOf(":") + 1, buildTarget.substring(0,buildTarget.lastIndexOf("|")).lastIndexOf("|"));
		epmBuildHistoryBean.setPartId(partId);
		
		Node buildRuleIdNode = doc.selectSingleNode("/EPMBuildHistory/buildRuleID");
		String buildRuleId = buildRuleIdNode.getText();
		epmBuildHistoryBean.setBuildRuleId(buildRuleId);
		
		return epmBuildHistoryBean;
	}
	
}
